"""
用户相关数据模型
"""

from typing import Optional
from pydantic import BaseModel, EmailStr, Field
from models.common import BaseEntity

class UserBase(BaseModel):
    """用户基础模型"""
    username: str = Field(..., min_length=3, max_length=50, description="用户名")
    name: str = Field(..., min_length=1, max_length=100, description="真实姓名")
    email: Optional[EmailStr] = Field(None, description="邮箱")
    phone: Optional[str] = Field(None, max_length=20, description="手机号")
    department: Optional[str] = Field(None, max_length=100, description="部门")
    position: Optional[str] = Field(None, max_length=100, description="职位")
    avatar: Optional[str] = Field(None, description="头像URL")

class UserCreate(UserBase):
    """创建用户模型"""
    password: str = Field(..., min_length=6, max_length=128, description="密码")

class UserUpdate(BaseModel):
    """更新用户模型"""
    name: Optional[str] = Field(None, min_length=1, max_length=100, description="真实姓名")
    email: Optional[EmailStr] = Field(None, description="邮箱")
    phone: Optional[str] = Field(None, max_length=20, description="手机号")
    department: Optional[str] = Field(None, max_length=100, description="部门")
    position: Optional[str] = Field(None, max_length=100, description="职位")
    avatar: Optional[str] = Field(None, description="头像URL")

class User(UserBase, BaseEntity):
    """用户响应模型"""
    status: int = Field(default=1, description="状态(1:正常 0:禁用)")
    
class UserInDB(User):
    """数据库中的用户模型"""
    password_hash: str = Field(..., description="密码哈希")

class UserSettings(BaseModel):
    """用户设置模型"""
    user_id: int
    theme: str = Field(default="light", description="主题设置")
    language: str = Field(default="zh-CN", description="语言设置")
    notifications_enabled: bool = Field(default=True, description="是否启用通知")
    auto_login: bool = Field(default=False, description="是否自动登录")
    
    class Config:
        from_attributes = True